#!/bin/bash

#获取当前时间
datetime=`date "+%Y-%m-%d %H:%M:%S"`

#读取IP列表行数
lineNumber=`cat iplist.txt |wc -l`

#设置计数参数
count=0

#清理历史ping测试记录结果
> ./ipcheckdown.txt

#循环读取IP并测试
for i in `cat ./iplist.txt`; do
        #计数器
        count=$((count+1))
        #控制台打印当前进度
        echo "${i} ${count}/${lineNumber}"
        #执行ping命令
        ping -c 1 -w 2 $i >> /dev/null
            if [ $? -eq 0 ]
                then
                    echo "${datetime}|${i}|true" >> ./ipcheckdown.txt
                else
                    echo "${datetime}|${i}|fail" >> ./ipcheckdown.txt
            fi
done